(function($) {
    $.fn.FeedEk = function(opt) {
        var def = $.extend({
            FeedUrl: "http://rss.cnn.com/rss/edition.rss",
            MaxCount: 5,
            ShowDesc: true,
            ShowPubDate: true,
            CharacterLimit: 0,
            TitleLinkTarget: "_blank",
            DateFormat: "",
            DateFormatLang: "en"
        }, opt);
        var id = $(this).attr("id"),
            i, s = "",
            dt;
        $("#" + id).empty().append('<img src="loader.gif" />');
        $.ajax({
            url: "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=" + def.MaxCount + "&output=json&q=" + encodeURIComponent(def.FeedUrl) + "&hl=en&callback=?",
            dataType: "json",
            success: function(data) {
                $("#" + id).empty();
                $.each(data.responseData.feed.entries, function(e, item) {
                    s += '<li><div class="itemTitle"><a href="' + item.link + '" target="' + def.TitleLinkTarget + '" >' + item.title + "</a></div>";
                    if (def.ShowPubDate) {
                        dt = new Date(item.publishedDate);
                        if ($.trim(def.DateFormat).length > 0) {
                            try {
                                moment.lang(def.DateFormatLang);
                                s += '<div class="itemDate">' + moment(dt).format(def.DateFormat) + "</div>"
                            } catch (e) {
                                s += '<div class="itemDate">' + dt.toLocaleDateString() + "</div>"
                            }
                        } else {
                            s += '<div class="itemDate">' + dt.toLocaleDateString() + "</div>"
                        }
                    }
                    if (def.ShowDesc) {
                        if (def.DescCharacterLimit > 0 && item.content.length > def.DescCharacterLimit) {
                            s += '<div class="itemContent">' + item.content.substr(0, def.DescCharacterLimit) + "...</div>"
                        } else {
                            s += '<div class="itemContent">' + item.content + "</div>"
                        }
                    }
                    
					/*var botones="<div class='btn-group btn-group-justified'> " +
					                 "<a onclick='verEntradaRSS("+"'codRss', '"+item.link+"', '"+decodeURI(cogerVariable(1))+"');' class='btn btn-primary'>Abrir</a>" +					
					                 "<a onclick='agregarEntradaFavorito();' class='btn btn-warning'>+ Favoritos</a>" +
					            "</div>";
					console.log(botones);
                    s +=" "+botones;*/
                    s +="<hr size='20px' color='black' />";
                });
                $("#" + id).append('<ul class="feedEkList" style="list-style:none;">' + s + "</ul>")
            }
        })
    }
})(jQuery);